/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.wisnu.tutorial.controller;

import com.wisnu.tutorial.model.Model;
import com.wisnu.tutorial.view.View;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Wisnu Wardoyo
 */
public class Controller {

    private final View view;
    List<Model> dataList = new ArrayList<>();

    public Controller() {
        view = new View();
        view.setController(this);
        tampilData();
        view.setVisible(true);

    }

    public final void tampilData() {
        String[] header = {"Nama", "Prodi"};
        String[][] dataTable = new String[dataList.size()][2];
        int i = 0;
        for (Model model : dataList) {
            dataTable[i][0] = model.getNama();
            dataTable[i][1] = model.getProdi();
            i++;
        }
        view.setTabelModel(new DefaultTableModel(dataTable, header));
    }

    public void tambahData() {
        Model model = new Model();
        model.setNama(view.getTxtNama().getText());
        model.setProdi(view.getTxtProdi().getText());
        dataList.add(model);
        tampilData();
    }

}
